import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:industry_net/pages/news/news_detail/widgets/comment_bar/state.dart';

class CommentController {
  final state = CommentState();
  VoidCallback? update;
  VoidCallback? reloadCallback;
  VoidCallback? forwardCallback;

  CommentController() {
    observer();
  }

  void observer() {
    state.focusNode.addListener(() {
      update!();
    });
    state.editCtrl.addListener(() {
      if (state.isEditing != state.editCtrl.text.isNotEmpty) {
        state.isEditing = state.editCtrl.text.isNotEmpty;
        update!();
      }
    });
  }

  void updateHinText(String hint) {
    state.hintText = hint;
    update!();
  }

  void actionPraise() {
    if (reloadCallback != null) {
      reloadCallback!();
    }
  }

  void actionCollect() {
    if (reloadCallback != null) {
      reloadCallback!();
    }
  }

  void actionForward() {
    if (forwardCallback != null) {
      forwardCallback!();
    }
  }

  void actionSend() {}
}
